In [12]:
import numpy as np
a = np.matrix([[1,2],[3,4]])
b = 2*np.eye(2)
In [14]:
a+b
Out[14]:
In [23]:
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
import math
%matplotlib inline
import matplotlib.pyplot as plt
model = Sequential()
model.add(Dense(8, input_dim=8, init='uniform',activation='linear'))
#model.add(Dense(4, activation='linear'))
model.add(Dense(4, activation='linear'))
model.compile(loss='mean_squared_error',optimizer='rmsprop',metrics=['accuracy'])
x_train = 100*(2*np.random.random((5000,8))-1)
y_train = x_train[:,0:4]+x_train[:,4:8]
hist = model.fit(x_train,y_train, nb_epoch=100, batch_size=30,verbose=0,shuffle=True, validation_split=0.2)
In [24]:
x_val = 100*(2*np.random.random((100,8))-1)
y_val = x_val[:,0:4]+x_val[:,4:8]
out = model.predict(x_val)
errors= np.mean(np.abs(y_val-out),axis=1)
#plt.scatter(range(len(errors)),errors,c='r',label='Accurate')
#plt.legend(loc=1)
plt.hist(errors)
plt.show()
In [25]:
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
import math
%matplotlib inline
import matplotlib.pyplot as plt
model = Sequential()
model.add(Dense(8, input_dim=8, init='uniform',activation='linear'))
#model.add(Dense(4, activation='linear'))
model.add(Dense(4, activation='linear'))
model.compile(loss='mean_squared_error',optimizer='rmsprop',metrics=['accuracy'])
x_train = 100*(2*np.random.random((5000,8))-1)
y_train = x_train[:,0:4]-x_train[:,4:8]
hist = model.fit(x_train,y_train, nb_epoch=100, batch_size=30,verbose=0,shuffle=True, validation_split=0.2)
In [26]:
x_val = 100*(2*np.random.random((100,8))-1)
y_val = x_val[:,0:4]-x_val[:,4:8]
out = model.predict(x_val)
errors= np.mean(np.abs(y_val-out),axis=1)
#plt.scatter(range(len(errors)),errors,c='r',label='Accurate')
#plt.legend(loc=1)
plt.hist(errors)
plt.show()
In [55]:
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
import math
%matplotlib inline
import matplotlib.pyplot as plt
model = Sequential()
model.add(Dense(16, input_dim=8, init='uniform',activation='linear'))
model.add(Dense(8, activation='linear'))
model.add(Dense(4, activation='linear'))
model.compile(loss='mean_squared_error',optimizer='rmsprop',metrics=['accuracy'])
x_train = 100*(2*np.random.random((5000,8))-1)
#y_train = x_train[:,0:4].dot(x_train[:,4:8])
y_train = np.array([x_train[i,0:4].reshape(2,2).dot(x_train[i,4:8].reshape(2,2)).reshape(1,4)[0] for i in range(len(x_train))])
hist = model.fit(x_train,y_train, nb_epoch=100, batch_size=30,verbose=0,shuffle=True, validation_split=0.2)
In [56]:
x_val = 100*(2*np.random.random((100,8))-1)
y_val = np.array([x_val[i,0:4].reshape(2,2).dot(x_val[i,4:8].reshape(2,2)).reshape(1,4)[0] for i in range(len(x_val))])
out = model.predict(x_val)
errors= np.mean(np.abs(y_val-out),axis=1)
#plt.scatter(range(len(errors)),errors,c='r',label='Accurate')
#plt.legend(loc=1)
plt.hist(errors)
plt.show()
In [6]:
import numpy as np
a = np.random.random(size=[3,3])
np.linalg.eigvals(a)
print a
np.reshape(a,(1,9))
Out[6]:
In [13]:
from keras.models import Sequential
from keras.layers import Dense
model = Sequential()
model.add(Dense(16, input_dim=9, init='uniform',activation='linear'))
model.add(Dense(8, activation='linear'))
model.add(Dense(3, activation='linear'))
model.compile(loss='mean_squared_error',optimizer='rmsprop',metrics=['accuracy'])
N = 500
x_train = np.random.random((N,9))
y_train = np.array([np.linalg.eigvals(np.reshape(matrix,(3,3))) for matrix in x_train])
hist = model.fit(x_train,y_train, nb_epoch=100, batch_size=30,verbose=1,shuffle=True, validation_split=0.2)
In [16]:
x_val = np.random.random((100,9))
y_val = np.array([np.linalg.eigvals(np.reshape(matrix,(3,3))) for matrix in x_val])
out = model.predict(x_val)
errors= np.mean(np.abs(y_val-out),axis=1)
%matplotlib inline
import matplotlib.pyplot as plt
#plt.scatter(range(len(errors)),errors,c='r',label='Accurate')
#plt.legend(loc=1)
plt.hist(errors)
plt.show()
In [ ]:
from keras.models import Sequential
from keras.layers import Dense
model = Sequential()
model.add(Dense(16, input_dim=9, init='uniform',activation='linear'))
model.add(Dense(8, activation='linear'))
model.add(Dense(3, activation='linear'))
model.compile(loss='mean_squared_error',optimizer='rmsprop',metrics=['accuracy'])
N = 500
x_train = np.random.random((N,9))
y_train = np.array([np.linalg.eigvals(np.reshape(matrix,(3,3))) for matrix in x_train])
hist = model.fit(x_train,y_train, nb_epoch=100, batch_size=30,verbose=1,shuffle=True, validation_split=0.2)